package com.zelma.house.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zelma.common.utils.PageUtils;
import com.zelma.common.utils.Query;

import com.zelma.house.dao.AreaDao;
import com.zelma.house.entity.AreaEntity;
import com.zelma.house.service.AreaService;


@Service("areaService")
@SuppressWarnings("all")
public class AreaServiceImpl extends ServiceImpl<AreaDao, AreaEntity> implements AreaService {

    @Autowired
    private AreaDao areaDao;

    @Override
    public List<AreaEntity> queryChildren(Integer id) {
//        查省
        List<AreaEntity> areaChildList = areaDao.selectList(new QueryWrapper<AreaEntity>().eq("parent_id", id));
//        遍历所有查出来的省份
        for (AreaEntity areaEntity : areaChildList) {
//            根据省的ID去查询市
            List<AreaEntity> areaEntities=this.queryChildrens(areaEntity.getId());
            areaEntity.setAreaChildrens(areaEntities);
        }
        return areaChildList;
    }


    private List<AreaEntity> queryChildrens(Integer id) {
//        查市->区->Null
        List<AreaEntity> childrenList = areaDao.selectList(new QueryWrapper<AreaEntity>().eq("parent_id", id));
        for (AreaEntity areaEntity : childrenList) {
            List<AreaEntity> areaEntities=this.queryChildrens(areaEntity.getId());
            areaEntity.setAreaChildrens(areaEntities);
        }
        return childrenList;
    }
}